#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QDir>
#include <QQuickWindow>
#include <QNetworkProxy>
#include <QSslConfiguration>
#include <QProcess>
#include <QtQml/qqmlextensionplugin.h>
#include <QLoggingCategory>
#include "AppInfo.h"
#include "src/component/CircularReveal.h"
#include "src/component/FileWatcher.h"
#include "src/helper/SettingsHelper.h"
#include <QDebug>
#include "src/model/sessionlistmodel.h"
#include "src/model/messagelistmodel.h"
#include "src/model/messagemodel.h"
#include "src/protocol/Packet.hpp"
#include "src/component/textareadocument.h"
int main(int argc, char *argv[])
{
    QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

    qputenv("QT_QUICK_CONTROLS_STYLE","Basic");
    QGuiApplication::setOrganizationName("CoWork");
    QGuiApplication::setOrganizationDomain("https://gitee.com/cnu-cowork-studio/cohub-client");
    QGuiApplication::setApplicationName("CoHub");
    SettingsHelper::getInstance()->init(argv);
    if(SettingsHelper::getInstance()->getRender()=="software")
        QQuickWindow::setGraphicsApi(QSGRendererInterface::Software);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

    SettingsHelper::getInstance()->init(argv);
    if(SettingsHelper::getInstance()->getRender()=="software"){
    QQuickWindow::setGraphicsApi(QSGRendererInterface::Software);
    }
    engine.rootContext()->setContextProperty("SettingsHelper",SettingsHelper::getInstance());
    qmlRegisterType<SessionModel>("IM", 1, 0, "SessionModel");
    qmlRegisterType<UserModel>("IM", 1, 0, "UserModel");
    qmlRegisterType<CircularReveal>("IM", 1, 0, "CircularReveal");
    qmlRegisterType<SessionListModel>("IM", 1, 0, "SessionListModel");
    qmlRegisterType<SessionListSortProxyModel>("IM", 1, 0, "SessionListSortProxyModel");
    qmlRegisterType<TextAreaDocument>("IM", 1, 0, "TextAreaDocument");
    qmlRegisterType<CircularReveal>("example", 1, 0, "CircularReveal");
    qmlRegisterType<FileWatcher>("example", 1, 0, "FileWatcher");
    qmlRegisterType<MessageListModel>("IM", 1, 0, "MessageListModel");
    qmlRegisterType<MessageListSortProxyModel>("IM", 1, 0, "MessageListSortProxyModel");
    const QUrl url(u"qrc:/cohub-client/main.qml"_qs);
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
        &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
